package org.feiye.studyday19.list;

import java.util.LinkedList;
import java.util.List;

public class LinkedList_NewsManger {

	public static void main(String[] args) {
		// 集合存储多条新闻标题
		NewsTitle title1 = new NewsTitle(1, "阿尔法狗大战李世石1", "admin1");
		NewsTitle title2 = new NewsTitle(2, "阿尔法狗大战李世石2", "admin2");
		NewsTitle title3 = new NewsTitle(3, "阿尔法狗大战李世石3", "admin3");
		NewsTitle title4 = new NewsTitle(4, "阿尔法狗大战李世石4", "admin4");
		NewsTitle title5 = new NewsTitle(5, "阿尔法狗大战李世石5", "admin5");
		NewsTitle title6 = new NewsTitle(6, "阿尔法狗大战李世石6", "admin6");
		NewsTitle title7 = new NewsTitle(7, "阿尔法狗大战李世石7", "admin7");
		// LinkedList的addFirst和addLast方法：添加头和尾；
		List list = new LinkedList();
		list.add(title1);
		list.add(title2);
		list.add(title3);
		list.add(title4);
		list.add(title5);
		list.add(1, title6);
		((LinkedList) list).addFirst(title4);
		((LinkedList) list).addLast(title1);
		list.add(title7);
		System.out.println(list.size());
		for (Object object : list) {
			NewsTitle title = (NewsTitle) object;
			System.out.println(title.getTitle());
		}
		System.out.println("*****************************");
		// LinkedList的removeFirst和removeLast方法：删除头和尾
		((LinkedList) list).removeFirst();
		for (Object object : list) {
			NewsTitle title = (NewsTitle) object;
			System.out.println(title.getTitle());
		}
		System.out.println("*****************************");
		((LinkedList) list).removeLast();
		for (Object object : list) {
			NewsTitle title = (NewsTitle) object;
			System.out.println(title.getTitle());
		}
		System.out.println("******************************");
		// LinkedList的getFirst和getLast方法：获得头和尾
		NewsTitle firstTitle = (NewsTitle) ((LinkedList) list).getFirst();
		System.out.println(firstTitle.getTitle());
		NewsTitle lastTitle = (NewsTitle) ((LinkedList) list).getLast();
		System.out.println(lastTitle.getTitle());
	}

}
